package adminlte.service;

import adminlte.model.Menu;
import adminlte.vo.MenuVo;
import adminlte.vo.ResponseData;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * @author ZHUFEIFEI
 */
@Service
public class MenuService {

    public List<MenuVo> getMenus() {
        return MenuVo.convert(this.menus());
    }

    private List<Menu> menus() {
        return Arrays.asList(
                new Menu(1L, 0L, "i'm header", null, null, true),
                new Menu(2L, 0L, "menu1", null),
                new Menu(3L, 0L, "menu2", null),
                //table1.html 基础的dataTable例子，固定静态数据
                new Menu(4L, 2L, "table1", "table/1.html"),
                //table2.html dataTable(bootstrap样式) 后台获取数据，并具有选中，自定义列，编辑功能
                new Menu(5L, 2L, "table2", "table/2.html"),
                //table3.html dataTable dataTable.editor.js 后台获取数据
                new Menu(6L, 2L, "table3", "table/3.html")
        );
    }

    public static void main(String[] args) throws JsonProcessingException {
        System.out.println(
                Jackson2ObjectMapperBuilder.json().build().writeValueAsString(
                ResponseEntity.ok(new MenuService().getMenus()).getBody()
                )
        );

        System.out.println(
                Jackson2ObjectMapperBuilder.json().build().writeValueAsString(
                        ResponseData.ok(new MenuService().getMenus())
                )
        );
    }

}
